<template>
  <div style="padding: 10px; width: 100%">
    <el-table :data="tableData" border stripe style="width: 100%" :row-class-name="tableRowClassName">
      <el-table-column type="selection" width="55" />
      <el-table-column prop="id" label="ID" />
      <el-table-column prop="name" label="考试名称" />
      <el-table-column prop="time" label="考试时间" />
      <el-table-column prop="type" label="考试类型" />
      <el-table-column prop="gradeName" label="考试年级" />
      <el-table-column prop="remark" label="备注" />
      <el-table-column label="操作" width="160px">
        <template #default="scope">
          <el-button
            @click="handleEdit(scope.row.id,scope.row.name)"
            size="mini"
            type="primary"
            plain
            >查看成绩</el-button
          >
        </template>
      </el-table-column>
    </el-table>
     <el-dialog
      :title=title
      v-model="scoreVisible"
      width="50%"
      :before-close="dialogClose">
      <el-table :data="scoreData" border stripe style="width: 100%" :summary-method="getSummaries"
    show-summary>
        <el-table-column prop="studentId" label="学号"></el-table-column>
        <el-table-column prop="studentName" label="姓名"></el-table-column>
        <el-table-column prop="courseName" label="科目"></el-table-column>
        <el-table-column prop="score" label="成绩"></el-table-column>
      </el-table>
    </el-dialog>
    <div style="margin: 10px 0">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import request from "../../utils/request";

export default {
  name: "Index",
  data() {
    return {
      disabled:false,
      scoreVisible:false,
      user: [],
      tableData: [],
      scoreData:[],
      gradeId:"",
      title:''
    };
  },
  created() {
    let str = sessionStorage.getItem("user") || "{}";
    this.user = JSON.parse(str);
    console.log(this.user);
    this.add()
    this.timer = setTimeout(()=>{    //设置延迟执行
         this.tableRowClassName(row)
        },300);   //0.2s
   
  },
  methods: {
    tableRowClassName(row,index){
      console.log("查询状态");
      console.log(row.row.status);
      
      if( row.row.status ==0){
        return 'hidden-row';
      }
      return '';
    },
    // 查询学生考试列表
    add() {
       request
        .get("/student/test", {
          params: {
            studentId: this.user.account,
          },
        })
        .then((res) => {
          console.log("查询考试列表");
          console.log(res);
          this.tableData = res.data.records
          for (let i = 0; i < res.data.records.length; i++) {
            // if(res.data.records[i].status ==1){
              
            // }
            this.tableData[i].gradeName = res.data.records[i].gradeList.name;
            if (res.data.records[i].type ==1) {
              this.tableData[i].type = "年级考试"
            }else{
              this.tableData[i].type = "平时考试"
            }
            
          }
        })
    },
    //查询成绩信息
    handleEdit(id,name){
      this.scoreVisible = true
      // 考试ID
      console.log(id);
      // 考试名称
      console.log(name);
      this.title =name
      // 当前用户账号
      console.log(this.user.account);
       request
        .get("/escore/studentscore", {
          params: {
            examId: id,
            studentId:this.user.account
          },
        })
        .then((res) => {
          console.log(res);
          this.scoreData = res.data
         
          for (let i = 0; i < res.data.length; i++) {
            this.scoreData[i].courseName = res.data[i].course.name;
            this.scoreData[i].studentName = res.data[i].student.stuName;
            this.scoreData[i].studentId = res.data[i].student.stuId
          }
        })
    }
  },
};
</script>

<style>
.a1 {
  font-size: 12px;
  text-align: center;
  margin-left: 20px;
}
.el-table .hidden-row {
    display: none;
  }

</style>

